/*******************************************************************************
 * Copyright (c) 2012, G. Weirich and Elexis
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    G. Weirich - initial implementation
 *******************************************************************************/

package ch.elexis.easy.developer.resources.model;

import ch.elexis.core.data.IPersistentObject;

public class PersistentObjectFactory extends ch.elexis.core.data.PersistentObjectFactory {
	
	@Override
	public IPersistentObject doCreateTemplate(Class typ){
		try {
			return (IPersistentObject) typ.newInstance();
		} catch (Exception ex) {
			return null;
		}
	}
	
	@Override
	public IPersistentObject createFromString(String code){
		String[] ci = code.split("::");
		Class clazz = getClassforName(ci[0]);
		if (clazz != null) {
			try {
				return (IPersistentObject) clazz.newInstance();
			} catch (Exception ex) {
				return null;
			}
		} else {
			return null;
		}
	}
	
	@Override
	public Class getClassforName(String fullyQualifiedClassName){
		try {
			return Class.forName(fullyQualifiedClassName);
		} catch (ClassNotFoundException e) {
			return null;
		}
	}
	
}
